<style type="text/css">
.form .control-label{ width:90px;}
.form legend{ line-height:20px; color:#F30; cursor:pointer}
.form legend span{ padding-left:20px; font-size:12px; color:#999;}
</style>
<?php		
	js::import($webRoot . 'js/ajaxfileupload.js', $config->version);
?>
 <div class="content_block_body" id="form_submit">
       <form class="form" method="post" name="__form" id="add_sites_form" encType="multipart/form-data">
       	<input type="hidden" value="<?php echo $sites_info->sites_id;?>" name="sites_id" />
        <fieldset>
       	 <legend id="legend1">基础配置<span>隐藏</span></legend>
         <div id="legend1_div">
            <div class="control-group">
                <label class="control-label" for="">站点名称:</label>
                <div class="controls">
                    <input type="text" name="sites_name"  class="input1" value="<?php echo $sites_info->sites_name;?>" style="width:300px;" require="true" datatype="require"  msg="站点名称不能为空" />
                </div>
            </div>
            
            <div class="control-group">
                <label class="control-label" for="">IPv6前缀:</label>
                <div class="controls">
                    <input type="text" name="pre_v6"  class="input1" value="<?php echo $sites_info->pre_v6;?>" style="width:300px;" require="true" datatype="require"  msg="IPv6前缀不能为空,格式如ipv6" />
                </div>
            </div>
            
            <div class="control-group">
                <label class="control-label" for="">主域名:</label>
                <div class="controls">
                    <input type="text" name="main_domain"  class="input1" value="<?php echo $sites_info->main_domain;?>" style="width:300px;" require="true" datatype="require"  msg="主域名不能为空,格式如baidu.com" />
                </div>
            </div>
            
            <div class="control-group">
                <label class="control-label" for="">访问类型及域名:</label>
                <div class="controls">
                    <select name="visit_type">
                        <option value="http" <?php if($sites_info->visit_type=='http'){echo 'selected="selected"';}?>>http://</option>
                        <option value="https" <?php if($sites_info->visit_type=='https'){echo 'selected="selected"';}?>>https://</option>
                    </select>
                    <input type="text" name="visit_domain"  class="input1" value="<?php echo $sites_info->visit_domain;?>" style="width:208px;" require="true" datatype="require"  msg="访问域名不能为空,格式如www.baidu.com" />
                </div>
            </div>
			
			<div class="control-group">
                <label class="control-label" for="">网站缩略图:</label>
                <div class="controls">
					<input type="hidden" name="site_img" id="site_img" value="<?php echo $sites_info->site_img;?>"/>
                    <input type="file" name="site_pic" id="fileToUpload" value="<?php echo $sites_info->site_pic;?>" class="input1" value=""/>
					<button id="buttonUpload">上传</button>
                </div>
            </div>

            <div class="control-group">
                <label class="control-label" for="">状态:</label>
                  <div class="controls">
                    <ul class="chunks" id="status_radio">
                        <li class="chunk <?php 
						if($sites_info->status=='1'||!isset($sites_info->status)){echo 'active';}?>" value="1"><a>启用</a></li>
                        <li class="chunk <?php 
						if($sites_info->status=='0'){echo 'active';}?>" value="0"><a>禁用</a></li>
                    </ul>
                    <input type="hidden" name="status" value="<?php 
						if($sites_info->status=='1'){echo '1';}else{ echo '0';}?>">
                 </div>
            </div>
        </div>
        
       </fieldset> 
       <fieldset>
       <legend id="legend2">扩展配置<span>显示</span></legend>
        <div id="legend2_div" style="display:none">
            
            <div class="control-group">
                <label class="control-label" for="">网站类型:</label>
                <div class="controls">
                    <select name="type_id">
                        <option value="" <?php if($sites_info->type_id==''){echo 'selected="selected"';}?>>网站类型未知</option>
                        <?php foreach($type_info as $key=>$val){?>
                        <option value="<?php echo $val->type_id;?>" <?php if($sites_info->type_id==$val->type_id){echo 'selected="selected"';}?>><?php echo $val->type_name?></option>
                        <?php }?>
                    </select>
                </div>
            </div>
            
            <div class="control-group">
                <label class="control-label" for="">所在区域:</label>
                <div class="controls">
                    <select name="area_id">
                    	<option value="" <?php if($sites_info->area_id==''){echo 'selected="selected"';}?>>省级区域未知</option>
                        <?php foreach($area_info as $key=>$val){?>
                        <option value="<?php echo $val->id;?>" <?php if($sites_info->area_id==$val->id){echo 'selected="selected"';}?>><?php echo $val->name?></option>
                        <?php }?>
                    </select>
                    <select name="area_id2" id="area_id2" data-value="<?php echo $sites_info->area_id2;?>">
                    	<option value="" <?php if($sites_info->area_id2==''){echo 'selected="selected"';}?>>市级区域未知</option>
                    </select>
                </div>
            </div>
            
            <div class="control-group">
                <label class="control-label" for="">所属单位:</label>
                <div class="controls">
                    <select name="unit_id" id="unit_id">
                        <option value="" <?php if($sites_info->unit_id==''){echo 'selected="selected"';}?>>所属单位未知</option>
                     <?php foreach($unit_info as $key=>$val){?>
                        <option value="<?php echo $val->unit_id;?>" <?php if($sites_info->unit_id==$val->unit_id){echo 'selected="selected"';}?>><?php echo $val->unit_name?></option>
                     <?php }?>
                    </select>
                    <a id="show_all_unit" href="javascript:void(0)" style="display:none">详细信息</a>
                </div>
            </div>
                  
            <div class="control-group">
                <label class="control-label" for="">备注:</label>
                <div class="controls">
                    <textarea name="sites_remark" style=" width:300px; height:60px;"><?php echo trim($sites_info->sites_remark);?></textarea>
                </div>
            </div>
        </div>
       </fieldset> 
    </form>
</div>
<script type="text/javascript">
	jQuery(function(){   
	    $("#buttonUpload").click(function(){     
		 // 加载图标   
		 /* $("#loading").ajaxStart(function(){
			$(this).show();
		 }).ajaxComplete(function(){
			$(this).hide();
		 });*/

		  // 上传文件
			var data = {name:'myname', description:'short description'} 
			$.ajaxFileUpload({
				url:'./upload.php',//处理图片脚本W
				secureuri :false,
				data: data,
				fileElementId :'fileToUpload',//file控件id
				dataType : 'json',
				success : function (data, status){
					console.log(data);
					console.log(status);
					$("#site_img").val(data);
					if(typeof(data.error) != 'undefined'){
						if(data.error != ''){
							alert(data.error);
						}else{
							alert(data.msg);
						}
					}
				},
				error: function(data, status, e){
					alert(e);
				}
			})
			return false;
		}) 
	})


	$(document).ready(function(e) {
		$("#status_radio a").click(function(){
			$("#status_radio li").removeClass('active');
			$(this).parent('li').addClass('active');
			var cvalue=$(this).parent('li').attr('value');
			$("#add_sites_form input[name=status]").val(cvalue);
		})
        $("#legend1").click(function(){
			var status=$("#legend1_div").css('display');
			$("#legend1_div").slideToggle()
			if(status=='block'){
				$("#legend1 span").html('显示')
			}else{
				$("#legend1 span").html('隐藏')
			}
		})
		$("#legend2").click(function(){
			var status=$("#legend2_div").css('display');
			$("#legend2_div").slideToggle()
			if(status=='block'){
				$("#legend2 span").html('显示')
			}else{
				$("#legend2 span").html('隐藏')
			}
		})
		
		function check_show_all_unit(){
			if($("#unit_id").val()==''){
				$("#show_all_unit").hide();
			}else{
				$("#show_all_unit").show();
			}
		}
		check_show_all_unit();
		//所属单位改变时
		$("#unit_id").change(function(){
			check_show_all_unit()
		})
		
		//地区信息改变时进行数据请求操作
		$("#add_sites_form select[name=area_id]").change(function(){
			var me=$(this),
			    thisvalue=me.val();
				$.post("index.php?m=updateopt&f=get_area2_info",{rid:thisvalue},
					function(data){
						var jsonobj=$.parseJSON(data);
						$("#area_id2").empty(); 
						if(jsonobj!=null){
							if(jsonobj.length!=0){
								$("#area_id2").show();
							}else{
								$("#area_id2").hide();
							}
							for(var i=0 ;i<jsonobj.length;i++){
								$("#area_id2").append("<option value='"+jsonobj[i].id+"'>"+jsonobj[i].name+"</option>");
							}
						}else{
							$("#area_id2").hide();
						}
						//$("#area_id2").val($("#area_id2").attr('data-value'));
				    });
		});
		$("#add_sites_form select[name=area_id]").change();
		//显示当前单位信息
		$("#show_all_unit").click(function(){
			$.dialog({
				lock:true,
				width:520,
				title:'单位详细信息',
				btn: {                      //可以任意定义按钮个数
				  cancle: {
					val: '取消'
				  }
				},
			 init:function(){
			    var that=this;
				 $.post("index.php?m=updateopt&f=show_unit",{unit_id:$("#unit_id").val()},
					function(data){
					    that.$content.html(data);
						that.$dialog.css('height','auto');
						/*that.$content.css('height','200');
						that.$content.css('overflow','auto');*/
				    });
			  }
			 });
		})
    });
</script>